﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;

namespace MMS
{
    public partial class Page_SelectBill : UIPage
    {
        public Page_SelectBill()
        {
            InitializeComponent();
        }
        db_mmsEntities conn = new db_mmsEntities();
        private void btn_Select_Click(object sender, EventArgs e)
        {
            uiDataGridView4.Rows.Clear();
            string meNumber = txt_MemNm.Text;
            string blNumber = txt_BillNb.Text;
            if (meNumber != "" && blNumber != "" || meNumber == "" && blNumber == "")
            {
                MessageBox.Show("请填写任意一项信息！");
            }
            else if(meNumber != ""&& blNumber == "")
            {
                //按会员卡号查询
                //查询会员卡号对应的流水号
                var metemp = conn.tb_consumer.Where(r => r.memberID == meNumber).ToList();
                foreach(var i in metemp)
                {
                    string billnumber = i.billID;
                    //按流水号查询
                    var temp = conn.tb_bill.Where(r => r.billsID == billnumber&&r.isShow==1).ToList();
                    addData(temp);
                }
            }
            else if (blNumber != ""&& meNumber == "")
            {
                //按流水号查询
                var temp = conn.tb_bill.Where(r => r.billsID == blNumber && r.isShow == 1).ToList();
                addData(temp);
            }
            txt_BillNb.Clear();
            txt_MemNm.Clear();
        }

        private void addData(List<tb_bill> temp)
        {
            foreach (var i in temp)
            {
                string[] str = new string[] { i.billsID, i.goodsInfo, i.goodsNumber.ToString(),i.billsMoney, i.billsTime.ToString(), i.operateName};
                uiDataGridView4.Rows.Add(str);
            }
        }
    }
}
